//
//  ZAgainPostView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/23.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZAgainPostView.h"
@interface ZAgainPostView ()<UIGestureRecognizerDelegate> {
    UIView * _whiteView;
    UILabel * _conTextLabel;
    UIButton * _backButton;
    UIButton * _aginPostButton;
}

@end
@implementation ZAgainPostView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}
 
- (void)initlizeInterface {
    [self makeAllSubView];
    [self addAllSubView];
    [self makeAllSubViewMasnoy];
    [self addTheTap];
}
- (void)makeAllSubView {
    self.backgroundColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:0.4];// 将背景设置为半透明
    _whiteView = [[UIView alloc] init];
    _whiteView.backgroundColor = [UIColor whiteColor];
    _conTextLabel = [[UILabel alloc] init];
    _conTextLabel.text = @"发送成功,所有回答均由专业注册执业医师基于发送内容解读,仅供参考,是否需要咨询其他医生？";
    _conTextLabel.font = [UIFont systemFontOfSize:18];
    _conTextLabel.numberOfLines = 0;
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _backButton.layer.cornerRadius = 3;
    _backButton.layer.borderWidth = 1;
    _backButton.layer.borderColor = [MYGREENColor CGColor];
    _backButton.layer.masksToBounds = YES;
    [_backButton setTitle:@"取消" forState:UIControlStateNormal];
    [_backButton setTitleColor:MYGREENColor forState:UIControlStateNormal];
    [_backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _aginPostButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _aginPostButton.layer.cornerRadius = 3;
    _aginPostButton.layer.masksToBounds = YES;
    
    [_aginPostButton addTarget:self action:@selector(AgainButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_aginPostButton setTitle:@"再次发布" forState:UIControlStateNormal];
    [_aginPostButton setBackgroundColor: MYGREENColor];
}
- (void)addAllSubView {
    [self addSubview:_whiteView];
    [self addSubview:_conTextLabel];
    [self addSubview:_backButton];
    [self addSubview:_aginPostButton];
}
- (void)makeAllSubViewMasnoy {
    [_whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.9);
        make.height.offset(200*xsIZE);
    }];
    [_conTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.width.equalTo(_whiteView);
        make.left.equalTo(_whiteView).offset(13*xsIZE);
        make.right.equalTo(_whiteView).offset(-13*xsIZE);
        make.top.equalTo(_whiteView);
        make.height.offset(120*ysIZE);
    }];
    [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_whiteView).offset(20*xsIZE);
        make.height.offset(30*ysIZE);
        make.bottom.equalTo(_whiteView).offset(-20*ysIZE);
        make.width.offset(100*xsIZE);
    }];
    [_aginPostButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_whiteView).offset(-20*ysIZE);
        make.centerY.height.equalTo(_backButton);
        make.width.offset(100*xsIZE);
    }];
}

// 半透明部分手势
- (void)addTheTap {
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(event:)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
}
- (void)event:(UITapGestureRecognizer *)gesture {
    [self removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isDescendantOfView:_backButton]||[touch.view isDescendantOfView:_aginPostButton]) {
        // 让其余控件 不响应此事件
        return NO;
    }
    return YES;
}

// 返回按钮的block
- (void)BackAction:(UIButton *)sender {
//    !self.BackHomeBlock? : self.BackHomeBlock();
    // 修改为取消
    [self removeFromSuperview];
}
// 继续发布的block
- (void)AgainButtonAction:(UIButton *)sender {
    !self.AgainPostBlock? :self.AgainPostBlock();
}
@end
